<?php
/**************************************************************************
 * Naanal PHP Framework, Simple, Efficient and Developer Friendly
 * Ver 3.0, Copyright (C) <2010>  <Tamil Amuthan. R>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ************************************************************************/
class ClsLXml extends ClsNaanalLibrary
{
    private $xmlData="";
    private $objXML=null;
    public function __construct($xmlData) {
        parent::__construct();
        $this->xmlData=$xmlData;
        $this->objXML = simplexml_load_string($xmlData) or die("Error: Can not create object from xml string");
    }
    /**
     * return node by path from root.
     * @param type $xpath
     * @param type $attributeName
     * Ex: /root/child/grand_child 
     */
    public function getData($xpath,$attributeName=false,$attributeValue=false)
    {
        if($element=$this->objXML->xpath($xpath))
        {
            return $this->xml2array($element);
        }
        return false;
    }
    private function &xml2array($element=false)
    {
        $arrXML = json_decode(json_encode((array) $element), 1);
        return $arrXML;
    }
    public function render()
    {
        
    }
}
?>